package com.example.mybatisplus.dynamic.controller;

import com.example.mybatisplus.dynamic.DynamicDataSource;
import com.example.mybatisplus.dynamic.domain.User;
import com.example.mybatisplus.dynamic.service.DynamicDataSourceSerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 动态数据源切换controller
 *
 * @Author longdeng
 * @Date 2020/9/22 0022 22:27
 */
@Controller
@RequestMapping("/api/ds")
public class DynamicDataSourceController {

    @Autowired
    private DynamicDataSourceSerivce dynamicDataSourceSerivce;

    @DynamicDataSource(value = "ds1")
    @RequestMapping("ds1")
    @ResponseBody
    public Object queryDs1(@RequestParam Map<String, Object> map) {
        List<User> userList = dynamicDataSourceSerivce.queryDs1(map);
        return userList;
    }

    @DynamicDataSource(value = "ds2")
    @RequestMapping("ds2")
    @ResponseBody
    public Object queryDs2(@RequestParam Map<String, Object> map) {
        List<User> userList = dynamicDataSourceSerivce.queryDs2(map);
        return userList;
    }

}
